import com.iocStu.dao.UserDaoImpl;
import com.iocStu.dao.UserDaoMySQLImpl;
import com.iocStu.pojo.*;
import com.iocStu.service.UserService;
import com.iocStu.service.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Mytest {

    @Test
    public void setUserDaoTest() {
        UserService userService = new UserServiceImpl();

        userService.setUserDao(new UserDaoImpl());
        userService.getUser();

        userService.setUserDao(new UserDaoMySQLImpl());
        userService.getUser();
    }


    @Test
    public void UserServiceImplTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

        UserServiceImpl userServiceImpl = (UserServiceImpl) context.getBean("UserServiceImpl");

        userServiceImpl.getUser();
    }


    @Test
    public void hello_SB_QWH_Test() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        Object hello = context.getBean("hello_SB_QWH");
        System.out.println(hello);


        Hello hello1 = new Hello();
        hello1.setStr("qwh是乖狗狗");
        System.out.println(hello1);


        Object helloTest = context.getBean("helloTest");
        System.out.println(helloTest);
    }

    @Test
    public void newUser() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        User user = (User) context.getBean("user");
        user.show();

    }


    //通过下标赋值
    @Test
    public void newConstructor() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        User user = (User) context.getBean("Constructor");
        System.out.println(user.toString());

    }
    //通过类型创建
//    @Test
//    public void newConstructorType() {
//        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
//        User user = (User) context.getBean("ConstructorType00");
//        System.out.println(user.toString());
//
//    }


    //通过name创建
    @Test
    public void newConstructorname() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        User user = (User) context.getBean("ConstructorName");
        user.show();

    }


    @Test
    public void aliasTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        User user = (User) context.getBean("ThisIsAlias");
        user.show();

    }

    @Test
    public void stuTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        Student student = (Student) context.getBean("student");//等价于 User user = context.getBean("user", User.class)
        System.out.println(student);
    }

    @Test
    public void userTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        User user = context.getBean("user", User.class);//
        System.out.println(user.toString());
    }

    @Test
    public void peopleTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        People people = context.getBean("people", People.class);
        System.out.println(people);
    }

    @Test
    public void testAuto() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        People people = context.getBean("people", People.class);
        people.getDog().shout();
        people.getCat().shout();

    }

    @Test
    public void annotationTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("annotationBeans.xml");
        People0 people0 = context.getBean("people0", People0.class);
        people0.getDog0();
        people0.getCat0();

    }

    @Test
    public void daoUserTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        com.iocStu.dao.User user = (com.iocStu.dao.User) context.getBean("user");
        System.out.println(user.name);
    }


}